Home:ALL Converter>sed to remove javascript call from minified html

sed to remove javascript call from minified html

Ask Time:2018-07-17T21:12:42         Author:unh

Json Formatter

I want to remove all external js call from minified html file. However, the following removes if js call is in another line (not works for minified html)

var=$(sed  -e '/^<script.*<\/script>$/d' -e '/.js/!d' testFile.html)
grep -v "$var" "testFile.html" | sponge "testFile.html"

Sample input file:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title> <script type="text/javascript" src="script.js" language="javascript"></script> <script></script> </head><body></body></html>

Sample output file:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title> <script></script> </head><body></body></html>

Thanks in advance

Author:unh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/51382304/sed-to-remove-javascript-call-from-minified-html
yy